﻿@page
@{ Layout = "_Layout"; }

<el-form :inline="true" :model="formInline" size="mini">
  <el-form-item label="角色">
    <el-select v-model="formInline.role" placeholder="管理员角色">
      <el-option label="<全部角色>" value=""></el-option>
      <el-option
        v-for="role in roles"
        :key="role.key"
        :label="role.value"
        :value="role.key">
      </el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="排序">
    <el-select v-model="formInline.order" placeholder="排序">
      <el-option label="<默认>" value=""></el-option>
      <el-option label="登录名称" value="UserName"></el-option>
      <el-option label="最后登录日期" value="LastActivityDate"></el-option>
      <el-option label="创建日期" value="CreatedDate"></el-option>
      <el-option label="登录次数" value="CountOfLogin"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="最后登录">
    <el-select v-model="formInline.lastActivityDate" placeholder="最后登录">
      <el-option label="<全部时间>" :value="0"></el-option>
      <el-option label="1天内" :value="1"></el-option>
      <el-option label="2天内" :value="2"></el-option>
      <el-option label="3天内" :value="3"></el-option>
      <el-option label="1周内" :value="7"></el-option>
      <el-option label="1个月内" :value="30"></el-option>
      <el-option label="3个月内" :value="90"></el-option>
      <el-option label="半年内" :value="180"></el-option>
      <el-option label="1年内" :value="365"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="关键字">
    <el-input v-model="formInline.keyword" placeholder="关键字"></el-input>
  </el-form-item>
  
  <el-form-item>
    <el-button type="primary" v-on:click="btnSearchClick">查询</el-button>
  </el-form-item>
</el-form>

<el-table
  :data="administrators"
  style="width: 100%">
  <el-table-column
    label="头像" width="80">
    <template slot-scope="scope">
      <el-link :underline="false" v-on:click="btnViewClick(scope.row)">
        <el-badge v-if="scope.row.locked" style="margin-top: 10px;" value="锁定">
          <el-avatar :size="40" :src="scope.row.avatarUrl || utils.getAssetsUrl('images/default_avatar.png')"></el-avatar>
        </el-badge>
        <el-avatar v-else :size="40" :src="scope.row.avatarUrl || utils.getAssetsUrl('images/default_avatar.png')"></el-avatar>
      </el-link>
    </template>
  </el-table-column>
  <el-table-column
    label="账号">
    <template slot-scope="scope">
      <el-link :underline="false" type="primary" v-on:click="btnViewClick(scope.row)">{{scope.row.userName}}</el-link>
    </template>
  </el-table-column>
  <el-table-column
    prop="displayName"
    label="姓名">
  </el-table-column>
  <el-table-column label="手机" width="120">
    <template slot-scope="scope">
      <div v-if="scope.row.mobile">
        {{ scope.row.mobile }}
        <el-tag v-if="scope.row.mobileVerified">已验证</el-tag>
        <el-tag v-else type="warning">待验证</el-tag>
      </div>
    </template>
  </el-table-column>
  <el-table-column
    width="180"
    prop="lastActivityDate"
    label="最后登录">
  </el-table-column>
  <el-table-column
    prop="countOfLogin"
    label="登录次数">
  </el-table-column>
  <el-table-column
    prop="roles"
    label="角色">
  </el-table-column>
  <el-table-column label="操作" width="350">
    <template slot-scope="scope">
      <el-button-group v-if="adminId !== scope.row.id">
        <el-button
          size="mini"
          v-on:click="btnEditClick(scope.row)">编辑</el-button>
        <el-button
          size="mini"
          v-on:click="btnPasswordClick(scope.row)">更改密码</el-button>
        <el-button
          size="mini"
          v-on:click="btnPermissionsClick(scope.row)">权限设置</el-button>
        <el-button
          v-if="scope.row.locked"
          size="mini"
          v-on:click="btnUnLockClick(scope.row)">解锁</el-button>
        <el-button
          v-else
          size="mini"
          v-on:click="btnLockClick(scope.row)">锁定</el-button>
        <el-button
          size="mini"
          type="danger"
          v-on:click="btnDeleteClick(scope.row)">删除</el-button>
      </el-button-group>
    </template>
  </el-table-column>
</el-table>

<div style="height: 10px"></div>

<el-row>
  <el-col :span="24" align="center">
    <el-pagination
      v-on:current-change="handleCurrentChange"
      :current-page="formInline.currentPage"
      hide-on-single-page
      :page-size="formInline.limit"
      layout="total, prev, pager, next, jumper"
      :total="count">
    </el-pagination>
  </el-col>
</el-row>

<el-divider></el-divider>
<div style="height: 10px"></div>

<el-button size="mini" type="primary" plain style="margin-left: 0px;" icon="el-icon-plus" v-on:click="btnAddClick">
  新 增
</el-button>
<el-button size="mini" type="primary" plain style="margin-left: 0px;" icon="el-icon-upload" v-on:click="btnImportClick">
  导 入
</el-button>
<el-button size="mini" type="primary" plain style="margin-left: 0px;" icon="el-icon-download" v-on:click="btnExportClick">
  导 出
</el-button>

<el-drawer
  title="权限设置"
  ref="drawer"
  :visible.sync="drawer"
  destroy-on-close
  direction="rtl"
  size="80%">
  <div class="drawer__content">
    <el-form ref="form" :model="permissionInfo" label-width="140px">
      <el-form-item label="管理员级别">
        <el-select v-model="permissionInfo.adminLevel" placeholder="请选择管理员级别">
          <el-option v-if="isSuperAdmin" label="超级管理员" value="SuperAdmin"></el-option>
          <el-option v-if="isSuperAdmin" label="站点管理员" value="SiteAdmin"></el-option>
          <el-option label="普通管理员" value="Admin"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="isSuperAdmin && permissionInfo.adminLevel === 'SiteAdmin'" label="可以管理的站点">
        <el-checkbox-group v-model="permissionInfo.checkedSites">
          <el-checkbox v-for="site in permissionInfo.allSites" :label="site.id" :key="site.id">{{site.siteName}}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item v-if="permissionInfo.adminLevel === 'Admin'" label="管理员角色">
        <el-transfer :titles="['可用角色', '管理员角色']" v-model="permissionInfo.checkedRoles" :data="permissionInfo.allRoles"></el-transfer>
      </el-form-item>
    </el-form>
    <div class="drawer__footer">
      <el-button type="primary" size="small" v-on:click="btnPermissionSubmitClick" :loading="permissionInfo.loading">{{ permissionInfo.loading ? '提交中 ...' : '确 定' }}</el-button>
      <el-button size="small" v-on:click="drawer = false">取 消</el-button>
    </div>
  </div>
</el-drawer>

<el-drawer
  title="导入管理员"
  ref="uploadPanel"
  :visible.sync="uploadPanel"
  destroy-on-close
  direction="rtl"
  size="50%">
  <div class="drawer__content">
    <br />
    <el-form ref="uploadForm" label-width="200px">
      <el-upload
        :drag="true"
        :limit="1"
        :action="$urlUpload"
        :auto-upload="true"
        :headers="{Authorization: 'Bearer ' + $token}"
        :file-list="uploadList"
        :before-upload="uploadBefore"
        :on-progress="uploadProgress"
        :on-success="uploadSuccess"
        :on-error="uploadError"
        :multiple="false">
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">
          <el-link :underline="false" type="primary" :href="utils.getAssetsUrl('uploadtemplates/管理员导入模版.xlsx')" target="_blank">
            <i class="el-icon-download"></i>
            下载导入模版
          </el-link>
        </div>
      </el-upload>
    </el-form>
  </div>
</el-drawer>

@section Scripts{
  <script src="/sitefiles/assets/js/admin/settings/administrators.js" type="text/javascript"></script>
}